//prody 预处理,相当于钩子函数
let obj = {
    add : function(val){
        return val+100;
    },
    name : 'I am Jspang'
};

console.log(obj.add(100));
console.log(obj.name);

let pro=new Proxy({
    add : function(val){
        return val+100;
    },
    name : 'I am Jspang'
},{
    //get,set,apply
    get : function(target,key,property){
        console.log('我进入了get!');
        console.log(target);
        
        //必须要 return
        return target[key];
    },
    set : function(target,key,value,receiver){
        console.log(` setting ${key} = ${value}`);
        console.log('我进入了set!');

        //必须要 return
        return target[key] = value;
    }
});

//获取值会首先调用get
console.log(pro.name);

//设置值会首先调用set
pro.name = '技术胖';
console.log(pro.name);

//apply
let target = function(){
    return 'I am JSPang';
}

let handler = {
    //apply 相当于直接的一个方法
    apply(target,ctx,args){
        console.log('do appply');
        return Reflect.apply(...arguments);
    }
}

let pro1 = new Proxy(target,handler);

console.log(pro1());